<template>
  <div class="content">
    <!-- 筛选区域 -->
    <el-row style="min-width:1366px;margin-bottom:24px">
      <el-col :span="8">
        <div>
          <span>企业名称</span>
          <el-input v-model="query.company_name" placeholder="输入企业名称筛选" />
        </div>
      </el-col>
      <el-col :span="8">
        <div>
          <span>联系方式</span>
          <el-input v-model="query.telephone" placeholder="输入联系方式筛选" />
        </div>
      </el-col>
      <el-col :span="8">
        <el-button class="filter" type="primary" plain @click="getAdministrationList">筛选</el-button>
        <el-button type="primary" plain class="reset" circle @click="reload">
          <i class="el-icon-refresh-right" />
        </el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-button type="primary" @click="getRegisterUrl">获得注册链接</el-button>
      <el-button type="primary" style="margin:0px;margin-left:40px" @click="toRouter">复用主体信息创建</el-button>
    </el-row>
    <!-- 表格区域 -->
    <el-table height="66.5vh" :data="administrationList" style="width: 100%;" :header-cell-style="{color:'black'}">
      <el-table-column label="商户ID" prop="uid" min-width="150px" />
      <el-table-column label="企业名称" prop="company_name" min-width="250px">
        <template v-slot="scope">
          <tool :content=" scope.row.company_name ">
            {{ scope.row.company_name }}
          </tool>
        </template>
      </el-table-column>
      <el-table-column label="企业类型" prop="company_type" min-width="100px">
        <template v-slot="scope">{{ companyTypeMap[scope.row.company_type_display] }}</template>
      </el-table-column>
      <el-table-column label="联系人" prop="contact" min-width="80px" />
      <el-table-column label="联系方式" prop="telephone" min-width="150px" />
      <el-table-column label="开户时间" prop="created_at" min-width="150px" />
      <el-table-column label="操作">
        <template v-slot="scope">
          <el-button type="text" @click="toChakan(scope.row.uid)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页区域 -->
    <div class="dingwei">
      <el-pagination
        :current-page="query.page"
        :page-sizes="$arrays.tableSize"
        :page-size="query.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <!-- 连接弹出框 -->
    <el-dialog title="分享邀请注册链接" :visible.sync="linkDialogVisible" width="30%">
      <el-input id="input" v-model="registerUrl" style="width:100%" :readonly="true" />
      <span slot="footer" class="dialog-footer">
        <el-button class="el-button-right" type="primary" @click="copyUrl">复制</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getAdministrationList, getRegisterUrl } from '@/api/merchant'
import tool from '@/components/tool'
export default {
  name: 'Administration',
  components: { tool },
  data() {
    return {
      administrationList: [],
      query: {
        company_name: '',
        telephone: '',
        page: 1,
        limit: 20
      },
      total: 0,
      companyTypeMap: {
        TRIP_COMPANY: '旅游公司',
        CAR_COMPANY: '用车公司',
        GEO_COMPANY: '景区商家',
        VISA_COMPANY: '签证商务公司',
        OTHER_COMPANY: '其他'
      },
      linkDialogVisible: false,
      registerUrl: ''
    }
  },
  created() {
    this.getAdministrationList()
  },
  methods: {
    getAdministrationList() {
      getAdministrationList(this.query).then((res) => {
        console.log(res)
        this.total = res.data.data.total
        this.administrationList = res.data.data.data
      })
    },
    handleSizeChange(newPageSize) {
      this.query.limit = newPageSize
      this.getAdministrationList()
    },
    handleCurrentChange(newPage) {
      this.query.page = newPage
      this.getAdministrationList()
    },
    reload() {
      this.query = {
        company_name: '',
        telephone: '',
        page: 1,
        limit: 20
      }
      this.getAdministrationList()
    },
    getRegisterUrl() {
      getRegisterUrl().then((res) => {
        this.registerUrl = res.data.data
        this.linkDialogVisible = true
      })
    },
    copyUrl() {
      var input = document.getElementById('input')
      input.select()
      document.execCommand('Copy')
    },
    toRouter() {
      this.$router.push({ name: 'multiplexing' })
    },
    toChakan(uid) {
      this.$router.push({ name: 'chakan', query: { uid: uid }})
    }
  }
}
</script>
<style lang="scss" scoped>
.content {
  width: 100%;
  padding: 24px;

  div {
    span {
      font-size: 16px;
      font-weight: bold;
      margin-right: 24px;
    }
    .el-input {
      width: calc(100% - 128px);
    }
  }
  .el-table {
    margin-top: 40px;
  }
  .filter {
    text-align: right;
    padding-right: 20px;
  }
  .el-pagination {
    margin-top: 16px;
  }
}
</style>

